package com.webchat.pgc.constants;


import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.webchat.common.constants.LocalCacheBase;
import com.webchat.domain.vo.response.mall.MallSKUDetailVO;
import com.webchat.pgc.service.mall.MallSPUService;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * 本地缓存常量池
 *
 */
public class LocalCacheConstants extends LocalCacheBase {

    /**
     * 电商商品详情本地一级缓存
     *
     */
    public static final Cache<Long, MallSKUDetailVO> MALL_PRODUCT_LOCAL_CACHE;

    static {
        MALL_PRODUCT_LOCAL_CACHE = CacheBuilder.newBuilder()
                                    .softValues()
                                    .expireAfterWrite(30, TimeUnit.MINUTES)
                                    .maximumSize(1000L)
                                    .build();

        cacheClassMap = new ConcurrentHashMap<>();
        cacheClassMap.put("MALL_PRODUCT_LOCAL_CACHE", MallSPUService.class);
    }


    public static void main(String[] args) {
        MALL_PRODUCT_LOCAL_CACHE.put(1L, new MallSKUDetailVO());
        MALL_PRODUCT_LOCAL_CACHE.getAllPresent(List.of(1L, 2L));
    }
}
